package com.wzx.user.utils.quartzUtils;

/**
 * @author wzx
 * @version 1.0
 * @date 2023/5/17 - 17:09
 * @description 标题
 */

import org.quartz.*;

import java.util.Date;

/**
 * @Description 定时任务测试类
 */
public class TestJob2 implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("定时任务2开始了："+new Date());
    }

    /**
     * @Description: 定时任务job2
     * @Param [scheduler]
     * @Return: void
     **/
    public void startJob2(Scheduler scheduler) throws SchedulerException {
        // 通过JobBuilder构建JobDetail实例，JobDetail规定只能是实现Job接口的实例
        // JobDetail 是具体Job实例
        JobDetail jobDetail = JobBuilder.newJob(TestJob2.class)
                .withIdentity("job2", "group2")
                .build();
        // 基于表达式构建触发器 //3s执行一次
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0/10 * * * * ?");
        // CronTrigger表达式触发器 继承于Trigger
        // TriggerBuilder 用于构建触发器实例
        CronTrigger cronTrigger = TriggerBuilder.newTrigger()
                .withIdentity("job2", "group2")
                .withDescription("测试任务描述job2")
                .withSchedule(cronScheduleBuilder)
                .build();
        scheduler.scheduleJob(jobDetail, cronTrigger);
    }
}
